home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Draw / TRRectObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  3.8 KB  |  173 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TRRectObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  12. ** on this function. */
  13.  
  14. /* This file implements the messages for the round-rect object.  Many of the messages
  15. ** can be handled by the rect object, as they deal with a rect structure.  Only
  16. ** a few of them are round-rect-specific. */
  17.  
  18. /* It would seem that you would want a custom hit-test message handler here, but
  19. ** the rect object first checks to see if the hit is within the bounding box of
  20. ** the object, and if so, it then calls the object to return the region.  This
  21. ** allows the rect object to generically handle hit-testing. */
  22.  
  23.  
  24.  
  25. /*****************************************************************************/
  26.  
  27.  
  28.  
  29. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  30. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  31. #include "App.protos.h"        /* Get the prototypes for the application.        */
  32.  
  33. #ifndef __OSEVENTS__
  34. #include <OSEvents.h>
  35. #endif
  36.  
  37. #ifndef __OSUTILS__
  38. #include <OSUtils.h>
  39. #endif
  40.  
  41. #ifndef __QUICKDRAW__
  42. #include <Quickdraw.h>
  43. #endif
  44.  
  45. #ifndef __STRING__
  46. #include <String.h>
  47. #endif
  48.  
  49. #ifndef __TREEOBJ2__
  50. #include "TreeObj2.h"
  51. #endif
  52.  
  53. #ifndef __UTILITIES__
  54. #include "Utilities.h"
  55. #endif
  56.  
  57.  
  58.  
  59. #pragma segment DrawObjects
  60. long    TRRectObj(TreeObjHndl hndl, short message, long data)
  61. {
  62.     Rect        rct;
  63.     RgnHandle    rgn;
  64.     short        w, h;
  65. #if VH_VERSION
  66.     char        *cptr;
  67. #endif
  68.  
  69.     switch (message) {
  70.         case FREEMESSAGE:
  71.         case COPYMESSAGE:
  72.         case UNDOMESSAGE:
  73.         case CONVERTMESSAGE:
  74.         case FREADMESSAGE:
  75.         case FWRITEMESSAGE:
  76.         case HREADMESSAGE:
  77.         case HWRITEMESSAGE:
  78.         case HITTESTMESSAGE:
  79.         case GETBBOXMESSAGE:
  80.         case SETBBOXMESSAGE:
  81.         case SECTBBOXMESSAGE:
  82.         case TARGETMESSAGE:
  83.         case CLICKMESSAGE:
  84.         case KEYMESSAGE:
  85.         case SETSELECTMESSAGE:
  86.         case GETSELECTMESSAGE:
  87.         case SIZEMESSAGE:
  88.             return(TRectObj(hndl, message, data));
  89.             break;
  90.  
  91.         case INITMESSAGE:
  92.             TRectObj(hndl, message, data);
  93.             mDerefRRect(hndl)->width = mDerefRRect(hndl)->height = 20;
  94.             break;
  95.  
  96.         case GETRGNMESSAGE:
  97.             rgn = NewRgn();
  98.             OpenRgn();
  99.             rct = mDerefRRect(hndl)->rect;
  100.             FrameRoundRect(&rct, mDerefRRect(hndl)->width, mDerefRRect(hndl)->height);
  101.             CloseRgn(rgn);
  102.             return((long)rgn);
  103.             break;
  104.  
  105.         case DRAWMESSAGE:
  106.             rct = mDerefRRect(hndl)->rect;
  107.             w   = mDerefRRect(hndl)->width;
  108.             h   = mDerefRRect(hndl)->height;
  109.             switch (data) {
  110.                 case DRAWOBJ:
  111.                     FillRoundRect(&rct, w, h, &qd.white);
  112.                     FrameRoundRect(&rct, w, h);
  113.                     break;
  114.                 case ERASEOBJ:
  115.                     EraseRoundRect(&rct, w, h);
  116.                     break;
  117.                 case DRAWSELECT:
  118.                     TRectObj(hndl, message, data);
  119.                     break;
  120.                 case DRAWGHOST:
  121.                     PenMode(patXor);
  122.                     FrameRoundRect(&rct, w, h);
  123.                     PenNormal();
  124.                     break;
  125.                 case DRAWMASK:
  126.                     FillRoundRect(&rct, w, h, &qd.black);
  127.                     break;
  128.             }
  129.             break;
  130.  
  131.         case PRINTMESSAGE:
  132.             TRRectObj(hndl, DRAWMESSAGE, DRAWOBJ);
  133.             break;
  134.  
  135. #if VH_VERSION
  136.         case VHMESSAGE:
  137.             cptr = ((VHFormatDataPtr)data)->data;
  138.             ccatchr(cptr, 13, 2);
  139.             ccat   (cptr, "$10: TRRectObj:");
  140.             ccatchr(cptr, 13, 1);
  141.             ccat   (cptr, "  $00: selected = ");
  142.             ccatdec(cptr, mDerefRRect(hndl)->selected);
  143.             ccatchr(cptr, 13, 1);
  144.             rct = mDerefRRect(hndl)->rect;
  145.             ccat   (cptr, "  $02: rect     = ($");
  146.             ccathex(cptr, 0, 4, 4, rct.top);
  147.             ccat   (cptr, ",$");
  148.             ccathex(cptr, 0, 4, 4, rct.left);
  149.             ccat   (cptr, ",$");
  150.             ccathex(cptr, 0, 4, 4, rct.bottom);
  151.             ccat   (cptr, ",$");
  152.             ccathex(cptr, 0, 4, 4, rct.right);
  153.             ccat   (cptr, ")");
  154.             ccatchr(cptr, 13, 1);
  155.             ccat   (cptr, "  $0A: width    = ");
  156.             ccatdec(cptr, mDerefRRect(hndl)->width);
  157.             ccatchr(cptr, 13, 1);
  158.             ccat   (cptr, "  $0C: height   = ");
  159.             ccatdec(cptr, mDerefRRect(hndl)->height);
  160.             return(true);
  161.             break;
  162. #endif
  163.  
  164.         default:
  165.             break;
  166.     }
  167.  
  168.     return(noErr);
  169. }
  170.  
  171.  
  172.  
  173.